package com.pc.controller;

import com.pc.Server.MQTTServer;
import com.pc.Server.RedisService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

//import static com.pc.config.PushCallback.mqttHashMap;

/**
 * @author 李林雨
 * @createTime 2023/6/2 16:37
 * @description
 */
@RestController
public class ChipController {
    @Resource
    private MQTTServer mqttserver;
    @Resource
    private RedisService redisService;

    @RequestMapping(value = "testPublish")
    public String testPublish(String topic, String msg, int qos) {
        mqttserver.sendMQTTMessage(topic, msg, qos);
        String data = "发送了一条主题是‘"+topic+"’，内容是:"+msg+"，消息级别 "+qos;
        return data;
    }

    /**
     * 订阅主题
     * @param topic 主题
     * @param qos 消息级别
     * @return
     */
    @RequestMapping(value = "testSubsribe")
    public String testSubsribe(String topic, int qos) {
        mqttserver.init(topic, qos);
        return "订阅主题'"+topic+"'成功";
    }




    @GetMapping("/hello1/{key}")
    public String hello1(@PathVariable String key){
        String key1 = redisService.getKey(key);
        return key1;
    }
    @GetMapping("/hello2/{K}/{V}")
    public void hello2(@PathVariable String K,@PathVariable String V){
        redisService.setKey(K,V);
    }


}
